home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / GLUT-3.7 / PROGS / EXAMPLES / SPHERE2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-12  |  1.6 KB  |  63 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1994. */
  3.  
  4. /* This program is freely distributable without licensing fees 
  5.    and is provided without guarantee or warrantee expressed or 
  6.    implied. This program is -not- in the public domain. */
  7.  
  8. #include <GL/glut.h>
  9.  
  10. GLfloat light_diffuse[] =
  11. {1.0, 0.0, 0.0, 1.0};
  12. GLfloat light_position[] =
  13. {1.0, 1.0, 1.0, 0.0};
  14. GLUquadricObj *qobj;
  15.  
  16. void
  17. display(void)
  18. {
  19.   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  20.   glCallList(1);        /* render sphere display list */
  21.   glutSwapBuffers();
  22. }
  23.  
  24. void
  25. gfxinit(void)
  26. {
  27.   qobj = gluNewQuadric();
  28.   gluQuadricDrawStyle(qobj, GLU_FILL);
  29.   glNewList(1, GL_COMPILE);  /* create sphere display list */
  30.   gluSphere(qobj, /* radius */ 1.0, /* slices */ 20,
  31.   /* stacks */ 20);
  32.   glEndList();
  33.   glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  34.   glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  35.   glEnable(GL_LIGHTING);
  36.   glEnable(GL_LIGHT0);
  37.   glEnable(GL_DEPTH_TEST);
  38.   glMatrixMode(GL_PROJECTION);
  39.   gluPerspective( /* field of view in degree */ 40.0,
  40.   /* aspect ratio */ 1.0,
  41.     /* Z near */ 1.0, /* Z far */ 10.0);
  42.   glMatrixMode(GL_MODELVIEW);
  43.   gluLookAt(0.0, 0.0, 5.0,  /* eye is at (0,0,5) */
  44.     0.0, 0.0, 0.0,      /* center is at (0,0,0) */
  45.     0.0, 1.0, 0.);      /* up is in positive Y direction */
  46.   glTranslatef(0.0, 0.0, -1.0);
  47. }
  48.  
  49. int
  50. main(int argc, char **argv)
  51. {
  52.   glutInit(&argc, argv);
  53.   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  54.   glutCreateWindow("sphere");
  55.   glutDisplayFunc(display);
  56.   gfxinit();
  57.   glutCreateWindow("a second window");
  58.   glutDisplayFunc(display);
  59.   gfxinit();
  60.   glutMainLoop();
  61.   return 0;             /* ANSI C requires main to return int. */
  62. }
  63.